<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件解析页面</title>
    <style>
        /* 全局样式 */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }

        /* 页面分为上下两部分 */
        .top-section, .bottom-section {
            width: 80%;
            max-width: 1200px;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        /* 按钮样式 */
        .button {
            padding: 10px 20px;
            margin-right: 10px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
        }

        .button.primary {
            background-color: #007bff;
            color: #fff;
        }

        .button.primary:hover {
            background-color: #0056b3;
        }

        .button.success {
            background-color: #28a745;
            color: #fff;
        }

        .button.success:hover {
            background-color: #218838;
        }

        /* 第二部分：文件内容和解析结果 */
        .bottom-section {
            display: flex;
            gap: 20px;
        }

        /* 文件内容展示 */
        .file-content {
            flex: 1;
            height: 400px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-family: Arial, sans-serif;
            font-size: 14px;
            resize: none; /* 禁止调整大小 */
            overflow-y: auto; /* 垂直滚动条 */
        }

        /* 解析结果展示 */
        .result-section {
            flex: 1;
        }

        .result-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        .result-table th,
        .result-table td {
            padding: 10px;
            border: 1px solid #ddd;
            text-align: left;
        }

        .result-table th {
            background-color: #f8f9fa;
            font-weight: bold;
            width: 30%;
        }

        /* 加载中弹窗 */
        .loading-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            justify-content: center;
            align-items: center;
        }

        .loading-content {
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            text-align: center;
        }
    </style>
</head>
<body>
<!-- 第一部分：按钮区域 -->
<div class="top-section">
    <button class="button primary" onclick="document.getElementById('file-upload').click()">选择文件</button>
    <button class="button success" onclick="parseFile()">解析文件</button>
    <input type="file" id="file-upload" style="display: none;">
</div>

<!-- 第二部分：文件内容和解析结果 -->
<div class="bottom-section">
    <!-- 文件内容展示 -->
    <div class="file-section">
        <h3>文件内容</h3>
        <textarea class="file-content" id="file-content" readonly></textarea>
    </div>

    <!-- 解析结果展示 -->
    <div class="result-section">
        <h3>解析结果</h3>
        <table class="result-table">
            <tbody>
            <tr><th>表头1</th><td>-</td></tr>
            <tr><th>表头2</th><td>-</td></tr>
            <tr><th>表头3</th><td>-</td></tr>
            <tr><th>表头4</th><td>-</td></tr>
            <tr><th>表头5</th><td>-</td></tr>
            <tr><th>表头6</th><td>-</td></tr>
            <tr><th>表头7</th><td>-</td></tr>
            <tr><th>表头8</th><td>-</td></tr>
            <tr><th>表头9</th><td>-</td></tr>
            <tr><th>表头10</th><td>-</td></tr>
            </tbody>
        </table>
    </div>
</div>

<!-- 加载中弹窗 -->
<div class="loading-modal" id="loading-modal">
    <div class="loading-content">
        <p>正在加载中...</p>
    </div>
</div>

<script>
    // 文件上传逻辑
    const fileUpload = document.getElementById('file-upload');
    const fileContent = document.getElementById('file-content');

    fileUpload.addEventListener('change', function (event) {
        const file = event.target.files[0];
        if (file) {
            // 清空文件内容
            fileContent.value = '';

            // 显示加载中弹窗
            const loadingModal = document.getElementById('loading-modal');
            loadingModal.style.display = 'flex';

            // 模拟后端请求（替换为实际的后端URL）
            const backendUrl = 'https://example.com/upload'; // 替换为实际的上传文件接口
            const formData = new FormData();
            formData.append('file', file);

            fetch(backendUrl, {
                method: 'POST',
                body: formData
            })
                .then(response => response.json())
                .then(data => {
                    // 隐藏加载中弹窗
                    loadingModal.style.display = 'none';

                    // 显示文件内容
                    if (data.fileContent) {
                        fileContent.value = data.fileContent;
                    } else {
                        alert('文件内容为空');
                    }
                })
                .catch(error => {
                    // 隐藏加载中弹窗
                    loadingModal.style.display = 'none';
                    alert('文件上传失败，请重试');
                    console.error('Error:', error);
                });
        }
    });

    // 解析文件逻辑
    function parseFile() {
        const file = fileUpload.files[0];
        if (!file) {
            alert('请先选择文件');
            return;
        }

        // 显示加载中弹窗
        const loadingModal = document.getElementById('loading-modal');
        loadingModal.style.display = 'flex';

        // 模拟后端请求（替换为实际的后端URL）
        const backendUrl = 'https://example.com/parse'; // 替换为实际的解析文件接口
        const formData = new FormData();
        formData.append('file', file);

        fetch(backendUrl, {
            method: 'POST',
            body: formData
        })
            .then(response => response.json())
            .then(data => {
                // 隐藏加载中弹窗
                loadingModal.style.display = 'none';

                // 更新表格数据
                const tableRows = document.querySelectorAll('.result-table tbody tr');
                tableRows.forEach((row, index) => {
                    const resultKey = `result${index + 1}`;
                    row.querySelector('td').textContent = data[resultKey] || '-';
                });
            })
            .catch(error => {
                // 隐藏加载中弹窗
                loadingModal.style.display = 'none';
                alert('解析失败，请重试');
                console.error('Error:', error);
            });
    }
</script>
</body>
</html>